home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / devices and hardware / disks / basicdiskimage / moreisbetterbits / moredisks.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  15.4 KB  |  391 lines

  1. /*
  2.     File:        MoreDisks.h
  3.  
  4.     Contains:    General disk driver utility routines.
  5.  
  6.     Written by:    Quinn
  7.  
  8.     Copyright:    Copyright © 1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.  
  20.          <6>    18/10/99    Quinn   Added target mode csCodes.
  21.          <5>     15/6/99    Quinn   Include "DriverGestalt.h" in here so that our clients don't have
  22.                                     to.
  23.          <4>      8/6/99    Quinn   Added some csCode that are reserved for the HDI driver.
  24.          <3>      7/5/99    Quinn   Added MoreIsDriveCDROM.
  25.          <2>      9/4/99    Quinn   Added more reserved _Control and _Status codes from the latest
  26.                                     Apple CD/DVD ERS.
  27.          <1>     16/3/99    Quinn   First checked in.
  28. */
  29.  
  30. #pragma once
  31.  
  32. /////////////////////////////////////////////////////////////////
  33. // MoreIsBetter Setup
  34.  
  35. #include "MoreSetup.h"
  36.  
  37. // Mac OS Interfaces
  38.  
  39. #include <MacTypes.h>
  40. #include <Devices.h>
  41. #include <DriverGestalt.h>
  42.  
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46.  
  47. /////////////////////////////////////////////////////////////////
  48. #pragma mark ----- Disk Driver Control/Status Codes -----
  49.  
  50. // Key to References:
  51. // 
  52. // o IM:Devices -- "Inside Macintosh: Devices"
  53. // o DV 17 -- DTS Technote DV 17 "What Your .Sony Driver Can Do For You"
  54. // o PCI C&Ds -- "Designing PCI Cards and Drivers for Power Macintosh Computers"
  55. // o TN1xxx -- Technote 1xxx "Disk Drivers, 1984 to 1999"
  56. // o "DriverGestalt.h" -- Documented (barely) in the "DriverGestalt.h" header file in Universal Interfaces.
  57. // o LPX-40 -- "Apple Logic Board Design LPX-40 Developer Note" (Tanzania),
  58. //             "MFM Floppy Disk Device Drive" chapter
  59. //             <http://developer.apple.com/techpubs/hardware/hardware2.html>
  60. // Entries that are commented out are already defined in Universal Interfaces.
  61.  
  62. enum {
  63.  
  64. //    Identifier                    Value        Reference
  65. //    ----------                    -----        ---------
  66.  
  67. //    ***** Control *****
  68.  
  69. //    goodbye                        = -1,        // IM:Devices
  70. //    killCode                    = 1,        // IM:Devices
  71. //    kVerify                        = 5,        // DV 17
  72. //    kFormat                        = 6,        // DV 17
  73. //    kEject                        = 7,        // DV 17
  74. //    kSetTagBuffer                = 8,        // DV 17
  75. //    kTrackCache                    = 9,        // DV 17
  76.     kPhysicalIOCode                = 17,        // TN1xxx, target mode
  77.     kGetIconID                    = 20,        // reserved (.Sony), do not use
  78. //    kDriveIcon                    = 21,        // DV 17
  79. //    kMediaIcon                    = 22,        // DV 17
  80. //    kDriveInfo                    = 23,        // DV 17
  81.     kHDIReserved1                = 24,        // reserved (HDI Driver - External Reference Specification), do not use
  82.     kHDIReserved2                = 25,        // reserved (HDI Driver - External Reference Specification), do not use
  83. //    kDriverConfigureCode        = 43,        // PCI C&Ds
  84.     kSetStartupPartition        = 44,        // TN1xxx
  85.     kSetStartupMount            = 45,        // TN1xxx
  86.     kLockPartition                = 46,        // TN1xxx
  87.     kClearPartitionMount        = 48,        // TN1xxx
  88.     kUnlockPartition            = 49,        // TN1xxx
  89. //    kRegisterPartition            = 50,        // TN1xxx
  90. //    kGetADrive                    = 51,        // TN1xxx
  91. //    kProhibitMounting            = 52,        // TN1xxx
  92. //    kIsContainerMounted            = 53,        // DriverGestalt.h
  93. //    kMountVolumeImg                = 54,        // DriverGestalt.h
  94.     kMountVolume                = 60,        // TN1xxx
  95. //    accRun                        = 65,        // IM:Devices
  96.     kSetPowerMode                = 70,        // PCI C&Ds
  97.     kModifyPostEvent            = 76,        // DV 22
  98.     kRawSCSICommand                = 77,        // reserved (.AppleCD), deprecated, not to be documented
  99.     kChooseIOStyle                = 78,        // reserved (.AppleCD), deprecated, not to be documented
  100.     kChangeBlockSize            = 79,        // DV 22
  101.     kSetUserEject                = 80,        // DV 22
  102.     kSetPollFrequency            = 81,        // DV 22
  103.     kReadTOC                    = 100,        // DV 22
  104.     kReadTheQSubcode            = 101,        // DV 22
  105.     kReadHeader                    = 102,        // DV 22
  106.     kAudioTrackSearch            = 103,        // DV 22
  107.     kAudioPlay                    = 104,        // DV 22
  108.     kAudioPause                    = 105,        // DV 22
  109.     kAudioStop                    = 106,        // DV 22
  110.     kAudioStatus                = 107,        // DV 22
  111.     kAudioScan                    = 108,        // DV 22
  112.     kAudioControl                = 109,        // DV 22
  113.     kReadMCN                    = 110,        // DV 22
  114.     kReadISRC                    = 111,        // DV 22
  115.     kReadAudioVolume            = 112,        // DV 22
  116.     kGetSpindleSpeed            = 113,        // DV 22
  117.     kSetSpindleSpeed            = 114,        // DV 22
  118.     kReadAudio                    = 115,        // DV 22
  119.     kReadAllSubcodes            = 116,        // DV 22
  120.     kSetTrackList                = 122,        // DV 22
  121.     kGetTrackList                = 123,        // DV 22
  122.     kGetTrackIndex                = 124,        // DV 22
  123.     kSetPlayMode                = 125,        // DV 22
  124.     kGetPlayMode                = 126,        // DV 22
  125.     kRawRead                    = 127,        // reserved (.AppleCD), do not use
  126.     kDiagnostics                = 127,        // reserved (.ATADisk), do not use
  127.     kSetQuiescentMode            = 1079,        // DV 22 (a future update will document this)
  128.     kEnableClose                = 16971,    // LPX-40 (Tanzania) Developer Note
  129.     kRetries                    = 17232,    // reserved (.Sony), do not use
  130. //    kRawTrack                    = 18244        // DV 17
  131.     kFormatCopy                    = 21315,    // LPX-40 (Tanzania) Developer Note
  132.     kAppleCDReserved1            = -130,        // reserved (Apple CD/DVD Driver ERS), do not use
  133.     kAppleCDReserved2            = -132,        // reserved (Apple CD/DVD Driver ERS), do not use
  134.     kAppleCDReserved5            = -301,        // reserved (Apple CD/DVD Driver ERS), do not use
  135.  
  136. //    ***** Status *****
  137.  
  138. //    kReturnFormatList            = 6,        // DV 17
  139. //    kDriveStatus                = 8,        // DV 17
  140. //    kMFMStatus                    = 10,        // LPX-40 (Tanzania) Developer Note
  141. //    kDriverGestaltCode            = 43,        // PCI C&Ds
  142.     kGetStartupStatus            = 44,        // TN1xxx
  143.     kGetMountStatus                = 45,        // TN1xxx
  144.     kGetLockStatus                = 46,        // TN1xxx
  145. //    kGetPartitionStatus            = 50,        // TN1xxx
  146. //    kGetPartInfo                = 51,        // TN1xxx
  147. //    kGetContainerAlias            = 52,        // DriverGestalt.h
  148.     kGetPowerMode                = 70,        // PCI C&Ds
  149.     kGet2KOffset                = 95,        // DV 22
  150.     kGetDriveType                = 96,        // DV 22
  151.     kResponsibleFor                = 97,        // DV 22
  152.     kGetBlockSize                = 98,        // DV 22
  153.     kGetSenseCode                = 99,        // reserved (.AppleCD), do not use
  154.     kReturnDeviceIdent            = 120,        // DV 22
  155.     kGetCDFeatures                = 121,        // DV 22
  156.     kGetErrorInfo                = 123,        // TN1xxx, target mode
  157.     kGetDriveInfo                = 124,        // TN1xxx, target mode
  158.     kGetDriveCapacity            = 125,        // TN1xxx, target mode
  159.     kLastErrorCode                = 127,        // reserved (.ATADisk), do not use
  160.     kGetQuiescentMode            = 1079,        // DV 22 (a future update will document this)
  161.     kSpeedCheck                    = 17232,    // reserved (.Sony), do not use
  162.     kDuplicatorVersionSupport    = 17494,    // LPX-40 (Tanzania) Developer Note
  163.     kLastFormByte                = 21315,    // LPX-40 (Tanzania) Developer Note
  164.     kAppleCDReserved3            = -129,        // reserved (Apple CD/DVD Driver ERS), do not use
  165.     kAppleCDReserved4            = -131,        // reserved (Apple CD/DVD Driver ERS), do not use
  166.     kAppleCDReserved6            = -300        // reserved (Apple CD/DVD Driver ERS), do not use
  167. };
  168.  
  169. /////////////////////////////////////////////////////////////////
  170. #pragma mark ----- Basic Disk Drive Utilities -----
  171.  
  172. #if PRAGMA_STRUCT_ALIGN
  173.     #pragma options align=mac68k
  174. #elif PRAGMA_STRUCT_PACKPUSH
  175.     #pragma pack(push, 2)
  176. #elif PRAGMA_STRUCT_PACK
  177.     #pragma pack(2)
  178. #endif
  179.  
  180. // This structure mirrors the 4 bytes of flags before the drive queue
  181. // element in memory.  The fields are documented in "Inside Macintosh:
  182. // Files":
  183. //
  184. //   <http://developer.apple.com/techpubs/mac/Files/Files-112.html>
  185. //
  186. // The comments here are a precis for your reference.
  187.  
  188. struct DriveFlags {
  189.     SInt8    writeProt;            // bit 7 set => write protected
  190.     SInt8    diskInPlace;        // 0 => no disk, 1 & 2 => ejectable disk, 8 => non-ejectable disk, $48 => non-ejectable disk but driver wants call, < 0 => disk in process of being ejected
  191.     SInt8    installed;            // "used internally during system startup"
  192.     SInt8    sides;                // bit 7 set => disk is single sided
  193. };
  194. typedef struct DriveFlags DriveFlags, *DriveFlagsPtr;
  195.  
  196. #if PRAGMA_STRUCT_ALIGN
  197.     #pragma options align=reset
  198. #elif PRAGMA_STRUCT_PACKPUSH
  199.     #pragma pack(pop)
  200. #elif PRAGMA_STRUCT_PACK
  201.     #pragma pack()
  202. #endif
  203.  
  204. extern pascal DriveFlagsPtr MoreGetDriveFlags(DrvQElPtr drvQEl);
  205.     // Returns the flags for a given drive queue element.  Note
  206.     // that this is a pointer to the real flags, not a copy.
  207.     // The pointer is valid only so long as the drive queue is
  208.     // valid.  Also, if you access the flags via this pointer,
  209.     // the flags will continually reflect the changes made
  210.     // by the driver.
  211.     //
  212.     // This routine is safe to call from all interrupt contexts.
  213.  
  214. extern pascal OSErr MoreUTFindDriveQ(SInt16 drive, DrvQElPtr *foundDrvQEl);
  215.     // A version of UTFindDrive that doesn't return extFSErr on
  216.     // non-HFS drive queue elements.  It also works regardless of
  217.     // whether FSM is installed or not.
  218.     //
  219.     // This really belongs in "MoreFSM.h", but it seems pointless
  220.     // to create that file just for this program.
  221.     //
  222.     // This routine is safe to call from all interrupt contexts.
  223.  
  224. extern pascal DrvQElPtr MoreGetIndDrive(SInt16 index);
  225.     // Returns the drive queue element of the index'th drive
  226.     // on the system, with index 1 being the first drive,
  227.     // or nil if there is no such drive.
  228.     //
  229.     // This routine is safe to call from all interrupt contexts.
  230.  
  231. extern pascal SInt16 MoreFindFreeDriveNumber(SInt16 firstDrive);
  232.     // Returns the first free drive number, starting
  233.     // from drive number firstDrive.  Drive numbers 
  234.     // below 5 are reserved, so you shoud pass 5 or
  235.     // more for firstDrive.  Typically hard disk drive
  236.     // numbers start from 8, although this is not required.
  237.     //
  238.     // This routine must be called at system task time,
  239.     // not because it is interrupt unsafe but because
  240.     // if you call it at interrupt time you might interrupt
  241.     // some other code that's allocating drive numbers
  242.     // and you might both get the same drive number!
  243.     
  244. extern pascal OSErr MoreRemoveDrive(DrvQElPtr drvQEl);
  245.     // This routine removes a drive queue element from the drive
  246.     // queue.  It's an adjunct to the system routine AddDrive;
  247.     // someone forgot to supply a to remove drive queue elements
  248.     // from the system.
  249.     //
  250.     // This routine returns volOnLinErr if there is a volume
  251.     // mounted on the drive.
  252.     //
  253.     // This routine must be called at system task time.
  254.     // Removing drive queue elements at interrupt time is
  255.     // unsafe because some non-interrupt code might be
  256.     // in the process of walking the drive queue.
  257.  
  258. extern pascal DriverRefNum MoreGetDriveRefNum(SInt16 drive);
  259.     // Walks the drive queue looking for the given drive
  260.     // and returns the driver reference number of the driver
  261.     // controlling the drive, or 0 if it wasn't found.
  262.     //
  263.     // This routine is safe to call from all interrupt contexts.
  264.  
  265. extern pascal Boolean MoreDriveSupportsDriverGestalt(SInt16 drive);
  266.     // Returns true if the driver controlling the
  267.     // specified drive supports Driver Gestalt.
  268.     //
  269.     // This routine must be called at system task time.
  270.     // It calls into TradDriverLoaderLib, which is not
  271.     // guaranteed to be interrupt safe.
  272.  
  273. extern pascal Boolean MoreDriveSupportFileExchange(SInt16 drive);
  274.     // Returns true if the driver controlling the specified
  275.     // drive support the File Exchange control call interface.
  276.     //
  277.     // This routine must be called at system task time.
  278.     // It makes synchronous Device Manager calls.
  279.  
  280. extern pascal OSErr MoreGetDriveSize(SInt16 drive, UInt32 *sizeInBlocks);
  281.     // Returns the size, in blocks, of the specified drive.
  282.     //
  283.     // Except for packaging and some cosmetic stuff, this
  284.     // is pretty much the same code as "GetDiskBlocks" from
  285.     // MoreFiles.
  286.     //
  287.     // This routine must be called at system task time.
  288.     // It makes synchronous Device Manager calls.
  289.  
  290. extern pascal SInt16 MoreVolumeMountedOnDrive(SInt16 drive, Boolean ejectedIsMounted);
  291.     // Returns the vRefNum of the volume mounted on the drive,
  292.     // or 0 if there are no volumes mounted on the drive.
  293.     //
  294.     // The ejectedIsMounted flag controls whether this routine
  295.     // considers an offline volume that was ejected from
  296.     // drive is still mounted on drive.  Typically you pass
  297.     // false to this parameter.  If you pass true, the routine
  298.     // will return the first offline volume that was ejected from
  299.     // drive.  There may be more than one.
  300.     //
  301.     // This routine walks the drive and VCB queues directly,
  302.     // so it's safe to call at interrupt time and when the
  303.     // the File System is busy.
  304.     //
  305.     // This routine is safe to call from all interrupt contexts.
  306.  
  307. extern pascal SInt16 MoreFirstDriveWithoutVolume(DriverRefNum refNum);
  308.     // Returns the drive number of the first drive in the drive
  309.     // queue which is controlled by refNum and which doesn't have
  310.     // a volume mounted on it, or 0 if there are no such drives.
  311.     //
  312.     // This routine is safe to call from all interrupt contexts.
  313.  
  314. typedef UInt32 MoreDisksCDROMResponse;
  315. enum {
  316.     kMoreDriveUnableToDetermineCDROM = 0,
  317.     kMoreDriveIsCDROM = 1,
  318.     kMoreDriveIsNotCDROM = 2
  319. };
  320.  
  321. extern pascal void MoreIsDriveCDROM(SInt16 drive, MoreDisksCDROMResponse *response);
  322.     // Sets *response to one of the constants shown above to indicate
  323.     // whether the drive is a CD-ROM drive.
  324.  
  325. /////////////////////////////////////////////////////////////////
  326. #pragma mark ----- File Exchange Control Call Interface -----
  327.  
  328. extern pascal OSErr MoreCreateNewDriveQueueElement(SInt16 driveToClone,
  329.                         UInt32 firstBlock, UInt32 sizeInBlocks,
  330.                         SInt16 *newDrive);
  331.     // Creates a new drive queue element controlled by the driver
  332.     // which is controlling driveToClone.  The firstBlock and sizeInBlocks
  333.     // parameters dictate where on the disk the drive queue element will
  334.     // access.  The drive number of the new drive queue element is returned
  335.     // in newDrive.
  336.     //
  337.     // driveToClone must support the File Exchange control call interface.
  338.     // If it doesn't, this routine will return an error.
  339.     //
  340.     // This routine must be called at system task time.
  341.     // It makes synchronous Device Manager calls.
  342.  
  343. extern pascal OSErr MoreSetDrivePartition(SInt16 drive, UInt32 firstBlock, UInt32 sizeInBlocks);
  344.     // Sets the partition on the disk which drive accesses.  This
  345.     // allows you to retarget drive to point to any range of blocks
  346.     // on the disk.  A high-level wrapper for the kRegisterPartition
  347.     // control call.
  348.     //
  349.     // drive must support the File Exchange control call interface.
  350.     // If it doesn't, this routine will return an error.
  351.     //
  352.     // This routine must be called at system task time.
  353.     // It makes synchronous Device Manager calls.
  354.  
  355. extern pascal OSErr MoreGetDrivePartition(SInt16 drive, UInt32 *firstBlock, UInt32 *sizeInBlocks);
  356.     // Returns the partition on the disk which the drive access.
  357.     //
  358.     // drive must support the File Exchange control call interface.
  359.     // If it doesn't, this routine will return an error.
  360.     //
  361.     // This routine must be called at system task time.
  362.     // It makes synchronous Device Manager calls.
  363.  
  364. extern pascal OSErr MoreGetPartitionInfo(SInt16 drive, partInfoRec *partInfo);
  365.     // Returns the File Exchange partInfoRec for the specified drive.
  366.     // A high-level wrapper for the kGetPartInfo status call.
  367.     //
  368.     // drive must support the File Exchange control call interface.
  369.     // If it doesn't, this routine will return an error.
  370.     //
  371.     // This routine must be called at system task time.
  372.     // It makes synchronous Device Manager calls.
  373.  
  374. extern pascal OSErr MoreGetPartitionVolume(DriverRefNum refNum, const partInfoRec *partInfo, SInt16 *vRefNum);
  375.     // Returns in vRefNum the volume which is mounted on the partition
  376.     // specified by partInfoRec.
  377.     //
  378.     // IMPORTANT: refNum is the driver reference number of the driver,
  379.     // *not* a drive number.  If you have a drive number, you can
  380.     // call MoreGetDriveRefNum to get the correct value.
  381.     //
  382.     // refNum must support the File Exchange control call interface.
  383.     // If it doesn't, this routine will return an error.
  384.     //
  385.     // This routine must be called at system task time.
  386.     // It makes synchronous Device Manager calls.
  387.     
  388. #ifdef __cplusplus
  389. }
  390. #endif
  391.